<style lang="less">
</style>

<template>
<div>
 <Card>  
        <p slot="title">
            <Icon type="navicon-round"></Icon>
            角色权限管理
        </p>
        <row>
            <i-col span="6">
    <Button-group>
        <Button @click="editusertype(0)">添加</Button>
        <Button @click="delduo">批量删除</Button>
    </Button-group></i-col>
            <i-col span="4">
            </i-col>
            
            <i-col span="14">
            </i-col>
        </row>
    <div style="margin-top:10px"></div>
    <i-table :columns="cols" :data="data" stripe @on-selection-change="setselect" @on-sort-change="setorder" ></i-table>
    
    <div style="margin-top:10px; text-align:center">
    <Page :total="pageinfo.total" :page-size="pageinfo.pagesize" show-sizer @on-change="pagechange" @on-page-size-change="pagesizechange"></Page></div>
    </Card>
    </div>
</template>

<script>
import api from '../../libs/api';
export default {
    name: 'usertype_index',
    data () {
        return {
            cols:[
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: 'ID',
                        key: 'ID',
                        width:60
                    },
                    {
                        title: '角色名',
                        key: 'typename',
                        align:'left',
                    render:(h,params)=>{
                        return h('Button',
                                    {
                                        props: {
                                            type: 'text',//无边框，像文字格式
                                            size: 'small',
                                        },
                                        on:{
                                                click: () => {            
                                                    this.editusertype(params.row.ID);
                                                }
                                            }
                                    },
                                    params.row.typename)
                    }
                    },
                    {
                        title: '系统角色',
                        key: 'system',
                        align:'center',
                        width:100,
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        width:'120px',
                        render: (h, params) => {
                            return h('div',
                                [
                                    h('Button',
                                        {
                                            props: {
                                                //type: 'text',//无边框，像文字格式
                                                size: 'small',
                                            },
                                            on: {
                                                click: () => {            
                                                    this.editusertype(params.row.ID);
                                                }
                                            }
                                        },
                                        '编辑'),
                                        h('span',' '),
                                    h('Button',
                                        {
                                            props: {
                                                //type: 'text',//无边框，像文字格式
                                                size: 'small',
                                            },
                                            on: {
                                                click: () => {
                                                    this.delusertype(params.index);
                                                }
                                            }
                                        },
                                        '删除')
                                ])
                        }
                    }],
            
            data:[],
            pageinfo:{page:1,pagesize:20,total:0,order:"ID",esc:"desc",key:'',classid:0},            
            categorys:[],
        };
    },
    methods:{
        pagesizechange(pagesize){
            this.pageinfo.pagesize=pagesize;
            this.init();
        },
        pagechange(page){
            this.pageinfo.page=page;
            this.init();
        },
        setorder(column){
            if(column.order=="normal"){
            this.pageinfo.order="ID";
            this.pageinfo.esc="desc";
            }
            else{
            this.pageinfo.order=column.key;
            this.pageinfo.esc=column.order;
            }
            this.init();
        },
        delusertype(index){
            var vm=this;            
            if(vm.data[index].ID==wlfData.userinfo.ID){
                this.$Message.error("不能删除自己！");
                return;
            }
            api.post("/admintype/del?id="+vm.data[index].ID).then(function(res){
                if(res.data.code==200){
                    vm.$Message.success(res.data.msg);
                }
                else{
                    vm.$Message.error(res.data.msg);
                }
                vm.init();
            })
        },
        setselect(selection){
            this.selectdata=selection;
        },
        delduo(){
            var vm=this; 
            api.post("/admintype/delall",{data:this.selectdata}).then(function(res){
                if(res.data.code==200){
                    vm.$Message.success("删除成功！");
                }
                vm.init();
            })
        },
        editusertype(id){                                          
            let query = {ID:id};
            this.$router.push({
                name: 'usertype_indexadd',
                query: query
            });  
        },
        getusertype(){
            var vm=this;
            api.post("/admintype/getlist?t="+new Date().getSeconds(),this.pageinfo).then(function(res){
                vm.data=res.data.msg.Items;
                vm.pageinfo.total=res.data.msg.TotalItems;
            })
        },
        init(){
                this.getusertype();
            // if(wlfData.userinfo.utype==1){
            // }
            // else{
            //     this.$Message.error("您没有访问权限！")                
            //     this.$router.push({
            //         name: 'error-403'
            //     });
            // }
        }
    },
    created(){
        this.init();
    },
    watch: {
        '$route' () {
            this.init();
        }
    }
};
</script>
